package com.oig.sys.auth.dao;

import com.oig.sys.auth.entity.TbUserRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbUserRoleDao extends JpaRepository<TbUserRole, Integer> {

	TbUserRole getByUserIdAndRoleId(Integer userId, Integer roleId);

	@Query("select f.roleId from TbUserRole f where f.userId=:userId")
	List<Integer> findByUserId(@Param("userId") Integer userId);

	@Query("select f.id from TbUserRole f where f.userId=:userId and f.id not in(:idList)")
	List<Integer> findAllIdByUserIdAndIdNotIN(@Param("userId") Integer userId, @Param("idList") List<Integer> idList);

	@Query("select f.id from TbUserRole f where f.roleId=:roleId")
	List<Integer> findAllIdByRoleId(@Param("roleId") Integer roleId);

	@Query("select f.id from TbUserRole f where f.userId=:userId")
	List<Integer> findAllIdByUserId(@Param("userId") Integer userId);

	@Modifying
	@Query("delete from TbUserRole f where f.id in(:idList)")
	void deleteByIdList(@Param("idList") List<Integer> idList);

}
